﻿using System.Collections.Generic;

namespace ObjetoNegocio
{
    public class Atributo:IObject
    {
        public List<Valor> Valores { get; set; }
        public string Nome { get; set; }
        public string Descricao { get; set; }
        public decimal Codigo { get; set; }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Atributo)) return false;
            return Equals((Atributo) obj);
        }

        public bool Equals(Atributo obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            var temp = Equals(obj.Nome, Nome) && Equals(obj.Descricao, Descricao) && obj.Codigo == Codigo;

            if(Valores != null && obj.Valores != null && Valores.Count == obj.Valores.Count)
            {
                for(int i=0;i<Valores.Count;i++)
                {
                    temp = Valores.Contains(obj.Valores[i]) && temp;
                }
            }
            else
            {
                temp = false;
            }

            return temp;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = (Valores != null ? Valores.GetHashCode() : 0);
                result = (result*397) ^ (Nome != null ? Nome.GetHashCode() : 0);
                result = (result*397) ^ (Descricao != null ? Descricao.GetHashCode() : 0);
                result = (result*397) ^ Codigo.GetHashCode();
                return result;
            }
        }
    }
}
